﻿using System;
#if USELINQ
using System.Linq;
#endif
using ICSharpCode.NRefactory.Ast;

namespace NTrace
{
    public static class TypeDeclarationExtensions
    {
        public static TypeReference CreateReference(
#if USELINQ
        this
#endif
        TypeDeclaration typeDeclaration)
        {
            TypeReference output;
            System.Diagnostics.Debug.Assert(typeDeclaration != null);
            if (typeDeclaration == null) throw new ArgumentNullException("typeDeclaration");

            if (typeDeclaration.Templates != null && typeDeclaration.Templates.Count > 0)
            {
                output = new TypeReference(
                    typeDeclaration.Name,
                    TemplateDefinitionExtensions.CreateReferenceList(typeDeclaration.Templates));
            }
            else
            {
                output = new TypeReference(typeDeclaration.Name);
            }

            return output;
        }
    }
}
